import requests
from lxml import etree

url = 'https://list.jiuxian.com/1-0-0-0-0-0-0-0-0-0-0-0.htm?area=2#v2'

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
}

ses = requests.session()
ses.get(url, headers=headers)  # 获取cookie

page = ses.get(url, headers=headers)
page_html = page.text  # 获取页面源码数据

with open('page.html', 'w', encoding='utf-8') as f:
    f.write(page_html)  # 保存页面源码数据

# print(page_html)
tree = etree.parse('page.html', etree.HTMLParser())  # 解析页面源码数据

urls = tree.xpath('//div[@class="content clearfix"]/div[@class="collect_box"]//img/@src')  # 重写xpath表达式

print(urls)  # 打印有结果

i = 0
for url in urls:
    img_data = ses.get(url).content  # 获取图片的二进制数据
    data_url = f'images/{i}.jpg'  # 图片保存路径
    with open(data_url, 'wb') as f:
        f.write(img_data)  # 保存图片
        i += 1
